package com.guan.study.easyExcelDemo.read.read01_简单读取;

import com.alibaba.excel.EasyExcel;
import com.guan.study.easyExcelDemo.Teacher;
import com.guan.study.easyExcelDemo.read.ReadLisitener;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Date: 2023/7/2 10:16
 * @Author: yaobai
 * @Description: 读取简单的excel内容，然后直接保存到数据库
 */
@RequestMapping("/readExcel01")
@RestController
@Log4j2
public class ReadExcel01 {

    @PostMapping("/import/teacher")
    public void importUserExcel(@RequestBody MultipartFile file) {
        try {
            ReadLisitener<Teacher> lisitener2 = new ReadLisitener<>();
            EasyExcel.read(file.getInputStream(), Teacher.class, lisitener2)
                   .sheet("新入职教师统计表")
                   .doRead();
            List<Teacher> list = lisitener2.getList();
            list.stream().forEach(v -> System.out.println(v));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
